﻿<UserControl x:Class="Export.Ui.Pages.OrderDetail"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             mc:Ignorable="d" 
             d:DesignHeight="600" d:DesignWidth="800">
    <Grid Style="{StaticResource ContentRoot}" Margin="16,28,16,0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="279*"/>
            <ColumnDefinition Width="55*"/>
            <ColumnDefinition Width="auto"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
        <Grid  Name="gridMenu"  IsEnabled="{Binding IsMenuEnable}" Height="30" Margin="10,10,10,0" VerticalAlignment="Top" Grid.ColumnSpan="3" Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>
            <TextBlock HorizontalAlignment="Left" Margin="19,10,0,0" TextWrapping="Wrap" Text="Location :" VerticalAlignment="Top" FontWeight="Bold"/>
            <ComboBox Grid.Column="1" HorizontalAlignment="Left" Margin="10,6,0,0" VerticalAlignment="Top" Width="150">
                <ComboBoxItem Content="สระบุรี"/>
                <ComboBoxItem Content="ระยอง"/>
            </ComboBox>
            <Button Content="Add" Grid.Column="2" HorizontalAlignment="Right" Margin="0,0,8,0" VerticalAlignment="Center" Width="75" Command="{Binding AddNewOrderDetailCommand}"/>
            <Button Command="{Binding DeleteOrderDetailCommand}" CommandParameter="{Binding SelectedItem, ElementName=orderDetailGrid}"  Content="Delete" Grid.Column="3" HorizontalAlignment="Right" Margin="0,0,0,0" VerticalAlignment="Center" Width="75"/>
        </Grid>

        <DataGrid SelectionMode="Single" IsReadOnly="{Binding IsGridReadOnly}" CanUserAddRows="False" Name="orderDetailGrid"  ItemsSource="{Binding OrdersDetails}" AutoGenerateColumns="False" Grid.ColumnSpan="3" Grid.Row="1" >
            <DataGrid.Columns>
                <DataGridTextColumn  Binding="{Binding OrderNo}" ClipboardContentBinding="{Binding OrderNo}" Header="OrderNo"/>
                <!--<DataGridTextColumn IsReadOnly="True" Binding="{Binding ItemNo}" ClipboardContentBinding="{Binding ItemNo}" Header="ItemNo"/>-->
                <!--<DataGridTextColumn  Binding="{Binding ProductId}" ClipboardContentBinding="{Binding ProductId}" Header="ProductId"/>-->
                <DataGridTextColumn  Binding="{Binding MaterialNo}" ClipboardContentBinding="{Binding MaterialNo}" Header="MaterialNo"/>
                <DataGridTextColumn  Binding="{Binding ItemId}" ClipboardContentBinding="{Binding ItemId}" Header="Product Name" />
                <DataGridTextColumn  Binding="{Binding Qty}" ClipboardContentBinding="{Binding Qty}" Header="Qty"/>
                <!--<DataGridTextColumn IsReadOnly="True" Binding="{Binding UnitPrice}" ClipboardContentBinding="{Binding UnitPrice}" Header="UnitPrice"/>
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding Amount}" ClipboardContentBinding="{Binding Amount}" Header="Amount"/>-->
                <DataGridTextColumn Binding="{Binding Plant}" ClipboardContentBinding="{Binding Plant}" Header="Plant"/>
                <DataGridTextColumn Binding="{Binding Atp , Mode=TwoWay}" ClipboardContentBinding="{Binding ATP}" Header="ATP"/>
                <DataGridTextColumn Binding="{Binding Rate}" ClipboardContentBinding="{Binding Rate}" Header="%"/>

                <DataGridTemplateColumn Header="Valid From" Width="100">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding ValidFrom, Mode=TwoWay,  UpdateSourceTrigger=LostFocus}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <DatePicker SelectedDate="{Binding ValidFrom, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Valid To" Width="100">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding ValidTo, Mode=TwoWay,
                                       UpdateSourceTrigger=LostFocus}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <DatePicker SelectedDate="{Binding ValidTo, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn ClipboardContentBinding="{x:Null}">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button  IsEnabled="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}, Path=DataContext.IsEnableCheckStock}" x:Name="ShowAtpDetailButton" Height="23" VerticalAlignment="Top" Cursor="Hand" Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}, Path=DataContext.ShowAptDetailCommand}" CommandParameter="{Binding}">...</Button>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>

        </DataGrid>
        <Button IsEnabled="{Binding IsEnableSave}" Content="Save" HorizontalAlignment="Right"  Grid.Row="2"  VerticalAlignment="Center" Width="75" Grid.ColumnSpan="1" Cursor="Hand" Command="{Binding SaveCommand}" Grid.Column="1" Margin="0,8,8,0"/>
        <Button Content="Close" HorizontalAlignment="Right"  Grid.Row="2"  VerticalAlignment="Center" Width="75" Command="{Binding CloseCommand}" Cursor="Hand" Grid.Column="2" Margin="0,8,0,0"/>
        <Button IsEnabled="{Binding IsEnableCheckStock}" Content="Update Stock" HorizontalAlignment="Left" Margin="0,8,0,0" Grid.Row="2" VerticalAlignment="Top"  Command="{Binding UpdateStockCommand}" />

        <Grid Height="28"  Grid.Row="2" VerticalAlignment="Bottom" Margin="0,8,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="auto" MinWidth="100"/>
            </Grid.ColumnDefinitions>
            <Button IsEnabled="{Binding IsEnableApprove}" Content="{Binding CaptionApprove}" Command="{Binding ApproveCommand}"  CommandParameter="{Binding SelectedItem, ElementName=orderDetailGrid}"  Grid.Column="1"  VerticalAlignment="Center" HorizontalAlignment="Right"  />
            <Button Visibility="{Binding VisibilityReject}" Content="Reject" Command="{Binding RejectCommand}" HorizontalAlignment="Right" VerticalAlignment="Center" Width="75" Grid.Column="0" Height="26" Margin="0,0,8,0"/>
        </Grid>
    </Grid>
</UserControl>
